﻿<?xml version="1.0" encoding="utf-8"?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ACompany.OrderProcessing.Model"
                   assembly="ACompany.OrderProcessing.Model">
  <class name="ACompany.OrderProcessing.Model.Customer" table="Customers" lazy="false">
    <id name="Id" column="id" type="guid">
      <generator class="guid" />
    </id>
    <property name="Name">
      <column name="Name" not-null="true" sql-type="varchar(50)" length="50" />
    </property>
    <property name="Email">
      <column name="EmailAddress" not-null="true" sql-type="varchar(50)" length="50" />
    </property>
    <component name="Address" class="Address">
      <property access="field.camelcase-underscore" name="Street">
        <column not-null="true" name="street" length="50" sql-type="varchar(50)" />
      </property>
      <property access="field.camelcase-underscore" name="City">
        <column not-null="true" name="city" length="50" sql-type="varchar(50)" />
      </property>
      <property access="field.camelcase-underscore" name="Country">
        <column name="Country" length="50" not-null="true" sql-type="varchar(50)" />
      </property>
      <property access="field.camelcase-underscore" name="PostCode">
        <column name="PostCode" length="50" sql-type="varchar(50)" not-null="true" />
      </property>
    </component>

    <!-- 
		    Note lazy load on the orders, We only want the orders
		    to be loaded from the database when we want them
		 -->
    <bag name="Orders" access="field.camelcase-underscore" inverse="true" cascade="none" order-by="Date" lazy="true">
      <key column="CustomerID" />
      <one-to-many class="Order" />
    </bag>

    <!-- One-to-many mapping: Addresses 
			need to add inverse="true" otherwise
			the SQL throws NULL error
			
			cascade="all-delete-orphan"
		-->


    <!--
		<bag name="Addresses" inverse="true" access="field.camelcase-underscore" cascade="all" lazy="false" >
			<key column="CustomerID" />
			<one-to-many class="CustomerAddress" />
		</bag>
		-->
  </class>

</hibernate-mapping>